package com.travel.admin.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.travel.admin.constants.App;
/**
 * 阿里云短信发送客户端
 */
public class AliyunSmsClient {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	/**
	 * 短信签名
	 */
	public static final String SIGN = "远东航空服务北京有限公司";
	/**
	 * 短信验证码模版
	 */
	public static final String SMS_463623092 = "SMS_463623092";
	public void execute(SendSmsRequest request){
		try {
			logger.info(new ObjectMapper().writeValueAsString(request));
			Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(App.ALIYUN_ACCESS_KEY_ID)
                // 您的AccessKey Secret
                .setAccessKeySecret(App.ALIYUN_ACCESS_KEY_SECRET);
        	// 访问的域名
        	config.endpoint = "dysmsapi.aliyuncs.com";
			Client client = new Client(config);
			SendSmsResponse sendSmsResponse = client.sendSms(request);
			if (sendSmsResponse != null) {
				logger.info("aliyun sms response:  {}", new ObjectMapper().writeValueAsString(sendSmsResponse));
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
